package org.example;

import org.example.basic.CoreCommunity;
import org.example.basic.TrussCommunity;

import java.io.*;
import java.util.Date;
import java.util.Scanner;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
        int x;
        Scanner scanner = new Scanner(System.in);
        x = scanner.nextInt();
        String str;
        if (x == 1) {
            str = "core";
        } else {
            str = "truss";
        }

        String inputFileName = "./src/main/java/org/example/data/com-youtube.ungraph.txt";
        String outputFileName = "./src/main/java/org/example/data/k-youtube-" + str + "-result.txt";
        String regex = "\t";

        int start = 1;
        try {
            BufferedReader reader = new BufferedReader(new FileReader(outputFileName));
            String line;
            while ((line = reader.readLine()) != null) {

                String[] words = line.split(" ");
                if (words.length > 0) {
                    start = Integer.parseInt(words[0].trim());
                    System.out.println("k=" + start + "跳过");
                }
            }

            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        if (start != 1)
            ++start;
        if (x == 1) {
            for (int i = start; i <= 120; ++i) {
                long timestamp1 = new Date().getTime(); // 获取当前时间的时间戳
                CoreCommunity coreCommunity = new CoreCommunity();
                coreCommunity.kCoreCommunitySearch(i, inputFileName, outputFileName, regex);
                long timestamp2 = new Date().getTime(); // 获取另一个时间的时间戳
                long diffSeconds = (timestamp2 - timestamp1); // 计算时间差（单位：毫秒）
                try {
                    String line = i + " " + diffSeconds + "\n";
                    FileWriter fileWriter = new FileWriter("./src/main/java/org/example/data/k-youtube-time-core.txt", true);
                    fileWriter.write(line);
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else {
            for (int i = start; i <= 30; ++i) {
                long timestamp1 = new Date().getTime(); // 获取当前时间的时间戳
                TrussCommunity trussCommunity = new TrussCommunity();
                trussCommunity.kTrussCommunitySearch(i, inputFileName, outputFileName, regex);
                long timestamp2 = new Date().getTime(); // 获取另一个时间的时间戳
                long diffSeconds = (timestamp2 - timestamp1); // 计算时间差（单位：毫秒）
                try {
                    String line = i + " " + diffSeconds + "\n";
                    FileWriter fileWriter = new FileWriter("./src/main/java/org/example/data/k-youtube-time-truss.txt", true);
                    fileWriter.write(line);
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
